#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<map>

using namespace std;

string minWindow(string s, string t) {
    if (t.size() > s.size()) return "";
    map<char, int> m1, m2;
    for (auto c : t) m2[c]++;

    auto check = [&]()->bool {
        for (auto it : m2)
            if (m1[it.first] < it.second)
                return false;
        return true;
    };

    int len = INT_MAX;
    string res;
    for (int l = 0, r = 0; r < s.size();)
    {
        while (r < s.size() && !check())
            m1[s[r++]]++;
        if ((r < s.size() || check()) && r - l + 1 < len)
        {
            len = r - l + 1;
            res = s.substr(l, r - l);
        }
        while (l < r && check())
            m1[s[l++]]--;
        if (l > 0 && r - l + 1 < len)
        {
            len = r - l + 1;
            res = s.substr(l - 1, len);
        }
    }
    return res;
}

int main()
{
    minWindow("cfabeca", "cae");
    return 0;
}